package DataAccess.Storage;

import java.io.Serializable;
import java.awt.*;
import java.util.*;

import DataAccess.DBAccessor;
import Element.*;
import Element.Geom.*;
import DistSys.*;

/**
 * Title:        iPAD
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:      ABB Inc.
 * @author Fangxing Li
 * @version 1.0
 */

public class ElemForStorage implements Serializable {
  public static final long serialVersionUID=100206L;

  //common to Element/Template
  protected String  sUniqueID;
  protected String  sName;
  protected String  sType;    //index linked to SysConst.ssType[]
  protected String  sDesc;

  //only for Element
  protected String  sDftTmplt;//index linked to Templates.allList;
  protected int     iX1;
  protected int     iY1;
  protected int     iX2;
  protected int     iY2;
  protected int     iRotation;
  protected int     iLTC;
  protected int     iSwitched;
  protected int     iIsOpen;
  protected int     iShowName;
  protected int     iShowDesc;
  protected int[]   iShowData = new int[10];
  protected int[]   iShowResult = new int[10];

  //only to Element
  protected String  sId;
  protected String  sConn1;
  protected String  sConn2;
  protected String  sConn3;

  //common to Element/Template
  protected double  dDataFontSize;        //"Base Font Size",                  // AbsElem.DATA_FONT_SIZE
  protected double  dDataConstCurrent;    //"Constant Current: Amps",          // AbsElem.DATA_CONST_CURR
  protected double  dDataConstPower;      //"Constant Power: kVA",             // AbsElem.DATA_CONST_POWER
  protected double  dDataCapitalCost;     //"Capital Cost: $",                 // AbsElem.DATA_CAPITAL_COST
  protected double  dDataCostPerSag;      //"Cost per Critical Sag: $",        // AbsElem.DATA_COST_PER_SAG
  protected double  dDataCostPerIntKW;    //"Cost per Interruption: $/kW",     // AbsElem.DATA_COST_PER_INT_KW
  protected double  dDataCostPerIntKWH;   //"Cost per Interruption: $/kWh",    // AbsElem.DATA_COST_PER_INT_KWH
  protected double  dDataVoltSagLevel;    //"Critical Voltage Sag: pu",        // AbsElem.DATA_VOLT_SAG_LEVEL
  protected double  dDataCustomers;       //"Customers",                       // AbsElem.DATA_CUSTOMERS
  protected double  dDataInOptLib;        //"In Optimization Library",         // AbsElem.DATA_IN_OPT_LIB
  protected double  dDataInstBlocked;     //"Instantaneous Blocked",           // AbsElem.DATA_INST_BLOCKED
  protected double  dDataIsLeading;       //"Lagging = 0, Leading = 1",        // AbsElem.DATA_IS_LEADING
  protected double  dDataLayer;           //"Layer",                           // AbsElem.DATA_LAYER
  protected double  dDataLength;          //"Length",                          // AbsElem.DATA_LENGTH
  protected double  dDataMaintDur;        //"Maintenance Duration: hr",        // AbsElem.DATA_MAINT_DUR
  protected double  dDataMaintRate;       //"Maintenance Rate: /yr",           // AbsElem.DATA_MAINT_RATE
  protected double  dDataMTTR;            //"Mean Time To Repair: hr",         // AbsElem.DATA_MTTR
  protected double  dDataMTTS;            //"Mean Time To Switch: hr",         // AbsElem.DATA_MTTS
  protected double  dDataNormalOpen;      //"Normally Open",                   // AbsElem.DATA_NORM_OPEN
  protected double  dDataNumBoostTaps;    //"# Boost Taps",                    // AbsElem.DATA_NUM_BOOST
  protected double  dDataNumBuckTaps;     //"# Buck Taps",                     // AbsElem.DATA_NUM_BUCK
  protected double  dDataOMCost;          //"O & M Cost: $/yr",                // AbsElem.DATA_OM_COST
  protected double  dDataOpenCircuits;    //"Open Circuits: /yr",              // AbsElem.DATA_OPEN_CKT
  protected double  dDataOperFailures;    //"Operational Failures: pu",        // AbsElem.DATA_OPER_FAIL
  protected double  dDataOptimizable;     //"Optimizable",                     // AbsElem.DATA_OPTIMIZABLE
  protected double  dDataPhase;           //"Phases (0-3)",                    // AbsElem.DATA_PHASE
  protected double  dDataPFConstCurrent;  //"PF of Constant Current",          // AbsElem.DATA_PF_CONST_CURR
  protected double  dDataPFConstPower;    //"PF of Constant Power",            // AbsElem.DATA_PF_CONST_POWER
  protected double  dDataRatedCurrent;    //"Rated Current: A",                // AbsElem.DATA_RATED_CURR
  protected double  dDataRatedPower;      //"Rated Power: kVA",                // AbsElem.DATA_RATED_POWER
  protected double  dDataReactance;       //"Reactance: Ohms",                 // AbsElem.DATA_REACTANCE
  protected double  dDataReclosingRelay;  //"Reclosing Relay",                 // AbsElem.DATA_RECLOSING
  protected double  dDataResistance;      //"Resistance: Ohms",                // AbsElem.DATA_RESISTANCE
  protected double  dDataShuntCond;       //"Shunt Conductance: Mhos",         // AbsElem.DATA_SHUNT_COND
  protected double  dDataShuntSucep;      //"Shunt Suceptance: Mhos",          // AbsElem.DATA_SHUNT_SUCEP
  protected double  dDataSourceVolt;      //"Source Voltage: kV",              // AbsElem.DATA_SRC_VOLT
  protected double  dDataStudyArea;       //"Study Area",                      // AbsElem.DATA_STUDY_AREA
  protected double  dDataPermFaultRate;   //"Sustained Faults: /yr",           // AbsElem.DATA_SUST_FAULT
  protected double  dDataBoostTrigger;    //"Tap Boost Trigger: kV",           // AbsElem.DATA_BOOST_TRIG
  protected double  dDataBuckTrigger;     //"Tap Buck Trigger: kV",            // AbsElem.DATA_BUCK_TRIG
  protected double  dDataTapRatio;        //"Tap Ratio: pu",                   // AbsElem.DATA_TAP_RATIO
  protected double  dDataTempFaultRate;   //"Temporary Faults: /yr",           // AbsElem.DATA_TEMP_FAULT
  protected double  dDataTxfmRatio;       //"Transformer Ratio: pu",           // AbsElem.DATA_TXFM_RATIO
  protected double  dDataUpgradeCost;     //"Upgrade Cost: $",                 // AbsElem.DATA_UPGRADE_COST
  protected double  dDataYear;            //"Year",                            // AbsElem.DATA_YEAR
  protected double  dDataZone;            //"Zone",                            // AbsElem.DATA_ZONE

  //only to Element
  protected int     iFlagFontSize;        //"Base Font Size",                  // AbsElem.DATA_FONT_SIZE
  protected int     iFlagConstCurrent;    //"Constant Current: Amps",          // AbsElem.DATA_CONST_CURR
  protected int     iFlagConstPower;      //"Constant Power: kVA",             // AbsElem.DATA_CONST_POWER
  protected int     iFlagCapitalCost;     //"Capital Cost: $",                 // AbsElem.DATA_CAPITAL_COST
  protected int     iFlagCostPerSag;      //"Cost per Critical Sag: $",        // AbsElem.DATA_COST_PER_SAG
  protected int     iFlagCostPerIntKW;    //"Cost per Interruption: $/kW",     // AbsElem.DATA_COST_PER_INT_KW
  protected int     iFlagCostPerIntKWH;   //"Cost per Interruption: $/kWh",    // AbsElem.DATA_COST_PER_INT_KWH
  protected int     iFlagVoltSagLevel;    //"Critical Voltage Sag: pu",        // AbsElem.DATA_VOLT_SAG_LEVEL
  protected int     iFlagCustomers;       //"Customers",                       // AbsElem.DATA_CUSTOMERS
  protected int     iFlagInOptLib;        //"In Optimization Library",         // AbsElem.DATA_IN_OPT_LIB
  protected int     iFlagInstBlocked;     //"Instantaneous Blocked",           // AbsElem.DATA_INST_BLOCKED
  protected int     iFlagIsLeading;       //"Lagging = 0, Leading = 1",        // AbsElem.DATA_IS_LEADING
  protected int     iFlagLayer;           //"Layer",                           // AbsElem.DATA_LAYER
  protected int     iFlagLength;          //"Length",                          // AbsElem.DATA_LENGTH
  protected int     iFlagMaintDur;        //"Maintenance Duration: hr",        // AbsElem.DATA_MAINT_DUR
  protected int     iFlagMaintRate;       //"Maintenance Rate: /yr",           // AbsElem.DATA_MAINT_RATE
  protected int     iFlagMTTR;            //"Mean Time To Repair: hr",         // AbsElem.DATA_MTTR
  protected int     iFlagMTTS;            //"Mean Time To Switch: hr",         // AbsElem.DATA_MTTS
  protected int     iFlagNormalOpen;      //"Normally Open",                   // AbsElem.DATA_NORM_OPEN
  protected int     iFlagNumBoostTaps;    //"# Boost Taps",                    // AbsElem.DATA_NUM_BOOST
  protected int     iFlagNumBuckTaps;     //"# Buck Taps",                     // AbsElem.DATA_NUM_BUCK
  protected int     iFlagOMCost;          //"O & M Cost: $/yr",                // AbsElem.DATA_OM_COST
  protected int     iFlagOpenCircuits;    //"Open Circuits: /yr",              // AbsElem.DATA_OPEN_CKT
  protected int     iFlagOperFailures;    //"Operational Failures: pu",        // AbsElem.DATA_OPER_FAIL
  protected int     iFlagOptimizable;     //"Optimizable",                     // AbsElem.DATA_OPTIMIZABLE
  protected int     iFlagPhase;           //"Phases (0-3)",                    // AbsElem.DATA_PHASE
  protected int     iFlagPFConstCurrent;  //"PF of Constant Current",          // AbsElem.DATA_PF_CONST_CURR
  protected int     iFlagPFConstPower;    //"PF of Constant Power",            // AbsElem.DATA_PF_CONST_POWER
  protected int     iFlagRatedCurrent;    //"Rated Current: A",                // AbsElem.DATA_RATED_CURR
  protected int     iFlagRatedPower;      //"Rated Power: kVA",                // AbsElem.DATA_RATED_POWER
  protected int     iFlagReactance;       //"Reactance: Ohms",                 // AbsElem.DATA_REACTANCE
  protected int     iFlagReclosingRelay;  //"Reclosing Relay",                 // AbsElem.DATA_RECLOSING
  protected int     iFlagResistance;      //"Resistance: Ohms",                // AbsElem.DATA_RESISTANCE
  protected int     iFlagShuntCond;       //"Shunt Conductance: Mhos",         // AbsElem.DATA_SHUNT_COND
  protected int     iFlagShuntSucep;      //"Shunt Suceptance: Mhos",          // AbsElem.DATA_SHUNT_SUCEP
  protected int     iFlagSourceVolt;      //"Source Voltage: kV",              // AbsElem.DATA_SRC_VOLT
  protected int     iFlagStudyArea;       //"Study Area",                      // AbsElem.DATA_STUDY_AREA
  protected int     iFlagPermFaultRate;   //"Sustained Faults: /yr",           // AbsElem.DATA_SUST_FAULT
  protected int     iFlagBoostTrigger;    //"Tap Boost Trigger: kV",           // AbsElem.DATA_BOOST_TRIG
  protected int     iFlagBuckTrigger;     //"Tap Buck Trigger: kV",            // AbsElem.DATA_BUCK_TRIG
  protected int     iFlagTapRatio;        //"Tap Ratio: pu",                   // AbsElem.DATA_TAP_RATIO
  protected int     iFlagTempFaultRate;   //"Temporary Faults: /yr",           // AbsElem.DATA_TEMP_FAULT
  protected int     iFlagTxfmRatio;       //"Transformer Ratio: pu",           // AbsElem.DATA_TXFM_RATIO
  protected int     iFlagUpgradeCost;     //"Upgrade Cost: $",                 // AbsElem.DATA_UPGRADE_COST
  protected int     iFlagYear;            //"Year",                            // AbsElem.DATA_YEAR
  protected int     iFlagZone;            //"Zone",                            // AbsElem.DATA_ZONE

  public ElemForStorage() { }

  //save
  public void copyFromElem(AbsElem elem, boolean bIsTmplt){
      AbsElemGeom geom = elem.getElemGeomObj();
      int iSwitched = 0;
      int iIsOpen =0;
      if( elem instanceof Switch3 && ((ThreeNodeElemGeom)geom).getIsSwitched() ){
          iSwitched = 1; }
      if( geom instanceof SwtGeom && ((SwtGeom)geom).getIsOpen() ){
          iIsOpen = 1; }

      this.sUniqueID = elem.getUniqueID();
      this.sName = geom.getName();
      this.sDesc = geom.getDesc();
      if( bIsTmplt){
          this.sType = SysConst.ssTemplType[SysConst.mapTemplTypeToIndex(elem.getType())];
      } else {
          this.sType = SysConst.ssTypeEngine[ elem.getType()];
          this.sDftTmplt = elem.getDftTempName();
          this.iX1 = geom.getX1Stored();
          this.iY1 = geom.getY1Stored();
          this.iX2 = geom.getX2Stored();
          this.iY2 = geom.getY2Stored();
          this.iRotation  = geom.getRotation(); //By default to south.
          this.iLTC       = geom.getLTC();
          this.iSwitched  = iSwitched;
          this.iIsOpen    = iIsOpen;
          this.iShowName  = geom.getShowName() ? 1 : 0;
          this.iShowDesc  = geom.getShowDesc() ? 1 : 0;
          this.storeShowText( elem );

          this.sId   = ""+ Sys.elemList.indexOf( elem ) ;
          this.sConn1= DBAccessor.buildConnIntoString( geom.conn1 );
          this.sConn2= DBAccessor.buildConnIntoString( geom.conn2 );
          if( geom instanceof ThreeNodeElemGeom){
              this.sConn3 = DBAccessor.buildConnIntoString(
                  ((ThreeNodeElemGeom)geom).conn3 );
          } else {
              this.sConn3=""; }
      }

      this.dDataFontSize       = elem.getData( AbsElem.DATA_FONT_SIZE );
      this.dDataConstCurrent   = elem.getData( AbsElem.DATA_CONST_CURR);
      this.dDataConstPower     = elem.getData( AbsElem.DATA_CONST_POWER );
      this.dDataCapitalCost    = elem.getData( AbsElem.DATA_CAPITAL_COST );
      this.dDataCostPerSag     = elem.getData( AbsElem.DATA_COST_PER_SAG );
      this.dDataCostPerIntKW   = elem.getData( AbsElem.DATA_COST_PER_INT_KW );
      this.dDataCostPerIntKWH  = elem.getData( AbsElem.DATA_COST_PER_INT_KWH );
      this.dDataVoltSagLevel   = elem.getData( AbsElem.DATA_VOLT_SAG_LEVEL );
      this.dDataCustomers      = elem.getData( AbsElem.DATA_CUSTOMERS );
      this.dDataInOptLib       = elem.getData( AbsElem.DATA_IN_OPT_LIB );
      this.dDataInstBlocked    = elem.getData( AbsElem.DATA_INST_BLOCKED );
      this.dDataIsLeading      = elem.getData( AbsElem.DATA_IS_LEADING );
      this.dDataLayer          = elem.getData( AbsElem.DATA_LAYER );
      this.dDataLength         = elem.getData( AbsElem.DATA_LENGTH );
      this.dDataMaintDur       = elem.getData( AbsElem.DATA_MAINT_DUR );
      this.dDataMaintRate      = elem.getData( AbsElem.DATA_MAINT_RATE );
      this.dDataMTTR           = elem.getData( AbsElem.DATA_MTTR );
      this.dDataMTTS           = elem.getData( AbsElem.DATA_MTTS );
      this.dDataNormalOpen     = elem.getData( AbsElem.DATA_NORM_OPEN );
      this.dDataNumBoostTaps   = elem.getData( AbsElem.DATA_NUM_BOOST );
      this.dDataNumBuckTaps    = elem.getData( AbsElem.DATA_NUM_BUCK );
      this.dDataOMCost         = elem.getData( AbsElem.DATA_OM_COST );
      this.dDataOpenCircuits   = elem.getData( AbsElem.DATA_OPEN_CKT );
      this.dDataOperFailures   = elem.getData( AbsElem.DATA_OPER_FAIL );
      this.dDataOptimizable    = elem.getData( AbsElem.DATA_OPTIMIZABLE );
      this.dDataPhase          = elem.getData( AbsElem.DATA_PHASE );
      this.dDataPFConstCurrent = elem.getData( AbsElem.DATA_PF_CONST_CURR );
      this.dDataPFConstPower   = elem.getData( AbsElem.DATA_PF_CONST_POWER );
      this.dDataRatedCurrent   = elem.getData( AbsElem.DATA_RATED_CURR );
      this.dDataRatedPower     = elem.getData( AbsElem.DATA_RATED_POWER );
      this.dDataReactance      = elem.getData( AbsElem.DATA_REACTANCE );
      this.dDataReclosingRelay = elem.getData( AbsElem.DATA_RECLOSING );
      this.dDataResistance     = elem.getData( AbsElem.DATA_RESISTANCE );
      this.dDataShuntCond      = elem.getData( AbsElem.DATA_SHUNT_COND );
      this.dDataShuntSucep     = elem.getData( AbsElem.DATA_SHUNT_SUCEP );
      //this.dDataSourceVolt     = elem.getData( AbsElem.DATA_SRC_VOLT );//zoe
      this.dDataStudyArea      = elem.getData( AbsElem.DATA_STUDY_AREA );
      this.dDataPermFaultRate  = elem.getData( AbsElem.DATA_SUST_FAULT );
      this.dDataBoostTrigger   = elem.getData( AbsElem.DATA_BOOST_TRIG );
      this.dDataBuckTrigger    = elem.getData( AbsElem.DATA_BUCK_TRIG );
      this.dDataTapRatio       = elem.getData( AbsElem.DATA_TAP_RATIO );
      this.dDataTempFaultRate  = elem.getData( AbsElem.DATA_TEMP_FAULT );
      this.dDataTxfmRatio      = elem.getData( AbsElem.DATA_TXFM_RATIO );
      this.dDataUpgradeCost    = elem.getData( AbsElem.DATA_UPGRADE_COST );
      this.dDataYear           = elem.getData( AbsElem.DATA_YEAR );
      this.dDataZone           = elem.getData( AbsElem.DATA_ZONE );

      //no need to set flag if elem is a Template
      if( bIsTmplt ) return;

      this.iFlagFontSize       = elem.getFlag( AbsElem.DATA_FONT_SIZE );
      this.iFlagConstCurrent   = elem.getFlag( AbsElem.DATA_CONST_CURR);
      this.iFlagConstPower     = elem.getFlag( AbsElem.DATA_CONST_POWER );
      this.iFlagCapitalCost    = elem.getFlag( AbsElem.DATA_CAPITAL_COST );
      this.iFlagCostPerSag     = elem.getFlag( AbsElem.DATA_COST_PER_SAG );
      this.iFlagCostPerIntKW   = elem.getFlag( AbsElem.DATA_COST_PER_INT_KW );
      this.iFlagCostPerIntKWH  = elem.getFlag( AbsElem.DATA_COST_PER_INT_KWH );
      this.iFlagVoltSagLevel   = elem.getFlag( AbsElem.DATA_VOLT_SAG_LEVEL );
      this.iFlagCustomers      = elem.getFlag( AbsElem.DATA_CUSTOMERS );
      this.iFlagInOptLib       = elem.getFlag( AbsElem.DATA_IN_OPT_LIB );
      this.iFlagInstBlocked    = elem.getFlag( AbsElem.DATA_INST_BLOCKED );
      this.iFlagIsLeading      = elem.getFlag( AbsElem.DATA_IS_LEADING );
      this.iFlagLayer          = elem.getFlag( AbsElem.DATA_LAYER );
      this.iFlagLength         = elem.getFlag( AbsElem.DATA_LENGTH );
      this.iFlagMaintDur       = elem.getFlag( AbsElem.DATA_MAINT_DUR );
      this.iFlagMaintRate      = elem.getFlag( AbsElem.DATA_MAINT_RATE );
      this.iFlagMTTR           = elem.getFlag( AbsElem.DATA_MTTR );
      this.iFlagMTTS           = elem.getFlag( AbsElem.DATA_MTTS );
      this.iFlagNormalOpen     = elem.getFlag( AbsElem.DATA_NORM_OPEN );
      this.iFlagNumBoostTaps   = elem.getFlag( AbsElem.DATA_NUM_BOOST );
      this.iFlagNumBuckTaps    = elem.getFlag( AbsElem.DATA_NUM_BUCK );
      this.iFlagOMCost         = elem.getFlag( AbsElem.DATA_OM_COST );
      this.iFlagOpenCircuits   = elem.getFlag( AbsElem.DATA_OPEN_CKT );
      this.iFlagOperFailures   = elem.getFlag( AbsElem.DATA_OPER_FAIL );
      this.iFlagOptimizable    = elem.getFlag( AbsElem.DATA_OPTIMIZABLE );
      this.iFlagPhase          = elem.getFlag( AbsElem.DATA_PHASE );
      this.iFlagPFConstCurrent = elem.getFlag( AbsElem.DATA_PF_CONST_CURR );
      this.iFlagPFConstPower   = elem.getFlag( AbsElem.DATA_PF_CONST_POWER );
      this.iFlagRatedCurrent   = elem.getFlag( AbsElem.DATA_RATED_CURR );
      this.iFlagRatedPower     = elem.getFlag( AbsElem.DATA_RATED_POWER );
      this.iFlagReactance      = elem.getFlag( AbsElem.DATA_REACTANCE );
      this.iFlagReclosingRelay = elem.getFlag( AbsElem.DATA_RECLOSING );
      this.iFlagResistance     = elem.getFlag( AbsElem.DATA_RESISTANCE );
      this.iFlagShuntCond      = elem.getFlag( AbsElem.DATA_SHUNT_COND );
      this.iFlagShuntSucep     = elem.getFlag( AbsElem.DATA_SHUNT_SUCEP );
     // this.iFlagSourceVolt     = elem.getFlag( AbsElem.DATA_SRC_VOLT );
      this.iFlagStudyArea      = elem.getFlag( AbsElem.DATA_STUDY_AREA );
      this.iFlagPermFaultRate  = elem.getFlag( AbsElem.DATA_SUST_FAULT );
      this.iFlagBoostTrigger   = elem.getFlag( AbsElem.DATA_BOOST_TRIG );
      this.iFlagBuckTrigger    = elem.getFlag( AbsElem.DATA_BUCK_TRIG );
      this.iFlagTapRatio       = elem.getFlag( AbsElem.DATA_TAP_RATIO );
      this.iFlagTempFaultRate  = elem.getFlag( AbsElem.DATA_TEMP_FAULT );
      this.iFlagTxfmRatio      = elem.getFlag( AbsElem.DATA_TXFM_RATIO );
      this.iFlagUpgradeCost    = elem.getFlag( AbsElem.DATA_UPGRADE_COST );
      this.iFlagYear           = elem.getFlag( AbsElem.DATA_YEAR );
      this.iFlagZone           = elem.getFlag( AbsElem.DATA_ZONE );
  }

  private void storeShowText(AbsElem elem){
      AbsElemGeom geom = elem.getElemGeomObj();
      for(int i=0; i<iShowData.length; i++){
          if( geom.getShowIndex(AbsElemGeom.SHOW_DATA)==false ||
              i >= geom.getShowIndexCount(AbsElemGeom.SHOW_DATA) ) {
              iShowData[i] = -1;
          } else {
              iShowData[i] = geom.getShowIndex(AbsElemGeom.SHOW_DATA, i);
          }
      }

      for(int i=0; i<iShowResult.length; i++){
          if( geom.getShowIndex( AbsElemGeom.SHOW_RESULT)==false ||
              i >= geom.getShowIndexCount(AbsElemGeom.SHOW_RESULT) ){
              iShowResult[i] = -1;
          } else {
              iShowResult[i] = geom.getShowIndex(AbsElemGeom.SHOW_RESULT, i);
          }
      }
  }//end of storeShowText(AbsElem elem)

  private void loadShowText( int[][] si ) {
      int cntr1=0, cntr2=0;
      int[] temp1 = new int[iShowData.length];
      int[] temp2 = new int[iShowResult.length];
      int index1, index2;
      for(int i=0; i<iShowData.length; i++){ //iShowData.len = iShowResult.len
          if( iShowData[i] >=0 ) { temp1[cntr1++] = iShowData[i];}
          if( iShowResult[i] >=0 ) { temp2[cntr2++] = iShowResult[i];}
      }

      if( cntr1 > 0 ){
          si[AbsElemGeom.SHOW_DATA] = new int[cntr1];
          System.arraycopy(temp1, 0, si[AbsElemGeom.SHOW_DATA],0, cntr1);
      } else {
          si[AbsElemGeom.SHOW_DATA] = null;
      }

      if( cntr2 > 0 ){
          si[AbsElemGeom.SHOW_RESULT] = new int[cntr2];
          System.arraycopy(temp2, 0, si[AbsElemGeom.SHOW_RESULT],0, cntr2);
      } else {
          si[AbsElemGeom.SHOW_RESULT] = null;
      }
  }//end of loadShowText( int[][] si )

  //loading
  public AbsElem createElemFromThis( boolean bIsTmplt ){
      AbsElem elem=null;
      AbsElemGeom geom=null;

      if( bIsTmplt ){
          elem = DBAccessor.constructTmpltAndItsGeom( this.sType );
          elem.getElemGeomObj().setName( this.sName );
          elem.getElemGeomObj().setDesc( this.sDesc);
      } else {
          //pre-processing
          Point p1=new Point( this.iX1, this.iY1); //for geom.init( )
          Point p2=new Point( this.iX2, this.iY2); //stored values
          boolean isOpen=false, isSwitched=false;
          if( this.iIsOpen == 1 ) { isOpen =true; }
          if( this.iSwitched == 1 ) { isSwitched =true; }
          boolean sn=false, sd=false; //show text
          if ( this.iShowName == 1 ) { sn = true;}
          if ( this.iShowDesc == 1 ) { sd = true; }
          int[][] si = new int[AbsElemGeom.NUM_SHOW][];
          if( iShowData != null ) { loadShowText( si ); }
          int iId = Integer.parseInt( this.sId );

          elem = DBAccessor.constructElemAndItsGeom(this.sType,
              this.sName, this.sDesc, this.iRotation, this.iLTC,
              sn, sd, si, p1, p2, isOpen, isSwitched);
          elem.setDftTemp( this.sDftTmplt );
      }
      elem.setUniqueID( this.sUniqueID );

      elem.setData( AbsElem.DATA_FONT_SIZE,       this.dDataFontSize );
      elem.setData( AbsElem.DATA_CONST_CURR,      this.dDataConstCurrent);
      elem.setData( AbsElem.DATA_CONST_POWER,     this.dDataConstPower );
      elem.setData( AbsElem.DATA_CAPITAL_COST,    this.dDataCapitalCost );
      elem.setData( AbsElem.DATA_COST_PER_SAG,    this.dDataCostPerSag );
      elem.setData( AbsElem.DATA_COST_PER_INT_KW, this.dDataCostPerIntKW );
      elem.setData( AbsElem.DATA_COST_PER_INT_KWH,this.dDataCostPerIntKWH );
      elem.setData( AbsElem.DATA_VOLT_SAG_LEVEL,  this.dDataVoltSagLevel );
      elem.setData( AbsElem.DATA_CUSTOMERS,       this.dDataCustomers );
      elem.setData( AbsElem.DATA_IN_OPT_LIB,      this.dDataInOptLib );
      elem.setData( AbsElem.DATA_INST_BLOCKED,    this.dDataInstBlocked );
      elem.setData( AbsElem.DATA_IS_LEADING,      this.dDataIsLeading );
      elem.setData( AbsElem.DATA_LAYER,           this.dDataLayer );
      elem.setData( AbsElem.DATA_LENGTH,          this.dDataLength );
      elem.setData( AbsElem.DATA_MAINT_DUR,       this.dDataMaintDur  );
      elem.setData( AbsElem.DATA_MAINT_RATE,      this.dDataMaintRate );
      elem.setData( AbsElem.DATA_MTTR,            this.dDataMTTR  );
      elem.setData( AbsElem.DATA_MTTS,            this.dDataMTTS );
      elem.setData( AbsElem.DATA_NORM_OPEN ,      this.dDataNormalOpen );
      elem.setData( AbsElem.DATA_NUM_BOOST,       this.dDataNumBoostTaps );
      elem.setData( AbsElem.DATA_NUM_BUCK,        this.dDataNumBuckTaps );
      elem.setData( AbsElem.DATA_OM_COST,         this.dDataOMCost );
      elem.setData( AbsElem.DATA_OPEN_CKT,        this.dDataOpenCircuits );
      elem.setData( AbsElem.DATA_OPER_FAIL ,      this.dDataOperFailures);
      elem.setData( AbsElem.DATA_OPTIMIZABLE ,    this.dDataOptimizable);
      elem.setData( AbsElem.DATA_PHASE ,          this.dDataPhase);
      elem.setData( AbsElem.DATA_PF_CONST_CURR ,  this.dDataPFConstCurrent);
      elem.setData( AbsElem.DATA_PF_CONST_POWER , this.dDataPFConstPower);
      elem.setData( AbsElem.DATA_RATED_CURR ,     this.dDataRatedCurrent);
      elem.setData( AbsElem.DATA_RATED_POWER ,    this.dDataRatedPower);
      elem.setData( AbsElem.DATA_REACTANCE ,      this.dDataReactance );
      elem.setData( AbsElem.DATA_RECLOSING ,      this.dDataReclosingRelay);
      elem.setData( AbsElem.DATA_RESISTANCE ,     this.dDataResistance);
      elem.setData( AbsElem.DATA_SHUNT_COND ,     this.dDataShuntCond );
      elem.setData( AbsElem.DATA_SHUNT_SUCEP ,    this.dDataShuntSucep);
      //elem.setData( AbsElem.DATA_SRC_VOLT ,       this.dDataSourceVolt);//deleted by Zoe
      elem.setData( AbsElem.DATA_STUDY_AREA ,     this.dDataStudyArea);
      elem.setData( AbsElem.DATA_SUST_FAULT ,     this.dDataPermFaultRate);
      elem.setData( AbsElem.DATA_BOOST_TRIG ,     this.dDataBoostTrigger);
      elem.setData( AbsElem.DATA_BUCK_TRIG ,      this.dDataBuckTrigger);
      elem.setData( AbsElem.DATA_TAP_RATIO ,      this.dDataTapRatio );
      elem.setData( AbsElem.DATA_TEMP_FAULT  ,    this.dDataTempFaultRate  );
      elem.setData( AbsElem.DATA_TXFM_RATIO ,     this.dDataTxfmRatio);
      elem.setData( AbsElem.DATA_UPGRADE_COST ,   this.dDataUpgradeCost );
      elem.setData( AbsElem.DATA_YEAR ,           this.dDataYear );
      elem.setData( AbsElem.DATA_ZONE ,           this.dDataZone );

      //no need to set flag if elem is a Template
      if( bIsTmplt ) { return elem; }

      elem.setFlag( AbsElem.DATA_FONT_SIZE,       this.iFlagFontSize );
      elem.setFlag( AbsElem.DATA_CONST_CURR,      this.iFlagConstCurrent);
      elem.setFlag( AbsElem.DATA_CONST_POWER,     this.iFlagConstPower );
      elem.setFlag( AbsElem.DATA_CAPITAL_COST,    this.iFlagCapitalCost );
      elem.setFlag( AbsElem.DATA_COST_PER_SAG,    this.iFlagCostPerSag );
      elem.setFlag( AbsElem.DATA_COST_PER_INT_KW, this.iFlagCostPerIntKW );
      elem.setFlag( AbsElem.DATA_COST_PER_INT_KWH,this.iFlagCostPerIntKWH );
      elem.setFlag( AbsElem.DATA_VOLT_SAG_LEVEL,  this.iFlagVoltSagLevel );
      elem.setFlag( AbsElem.DATA_CUSTOMERS,       this.iFlagCustomers );
      elem.setFlag( AbsElem.DATA_IN_OPT_LIB,      this.iFlagInOptLib );
      elem.setFlag( AbsElem.DATA_INST_BLOCKED,    this.iFlagInstBlocked );
      elem.setFlag( AbsElem.DATA_IS_LEADING,      this.iFlagIsLeading );
      elem.setFlag( AbsElem.DATA_LAYER,           this.iFlagLayer );
      elem.setFlag( AbsElem.DATA_LENGTH,          this.iFlagLength );
      elem.setFlag( AbsElem.DATA_MAINT_DUR,       this.iFlagMaintDur  );
      elem.setFlag( AbsElem.DATA_MAINT_RATE,      this.iFlagMaintRate );
      elem.setFlag( AbsElem.DATA_MTTR,            this.iFlagMTTR  );
      elem.setFlag( AbsElem.DATA_MTTS,            this.iFlagMTTS );
      elem.setFlag( AbsElem.DATA_NORM_OPEN ,      this.iFlagNormalOpen );
      elem.setFlag( AbsElem.DATA_NUM_BOOST,       this.iFlagNumBoostTaps );
      elem.setFlag( AbsElem.DATA_NUM_BUCK,        this.iFlagNumBuckTaps );
      elem.setFlag( AbsElem.DATA_OM_COST,         this.iFlagOMCost );
      elem.setFlag( AbsElem.DATA_OPEN_CKT,        this.iFlagOpenCircuits );
      elem.setFlag( AbsElem.DATA_OPER_FAIL ,      this.iFlagOperFailures);
      elem.setFlag( AbsElem.DATA_OPTIMIZABLE ,    this.iFlagOptimizable);
      elem.setFlag( AbsElem.DATA_PHASE ,          this.iFlagPhase);
      elem.setFlag( AbsElem.DATA_PF_CONST_CURR ,  this.iFlagPFConstCurrent);
      elem.setFlag( AbsElem.DATA_PF_CONST_POWER , this.iFlagPFConstPower);
      elem.setFlag( AbsElem.DATA_RATED_CURR ,     this.iFlagRatedCurrent);
      elem.setFlag( AbsElem.DATA_RATED_POWER ,    this.iFlagRatedPower);
      elem.setFlag( AbsElem.DATA_REACTANCE ,      this.iFlagReactance );
      elem.setFlag( AbsElem.DATA_RECLOSING ,      this.iFlagReclosingRelay);
      elem.setFlag( AbsElem.DATA_RESISTANCE ,     this.iFlagResistance);
      elem.setFlag( AbsElem.DATA_SHUNT_COND ,     this.iFlagShuntCond );
      elem.setFlag( AbsElem.DATA_SHUNT_SUCEP ,    this.iFlagShuntSucep);
     // elem.setFlag( AbsElem.DATA_SRC_VOLT ,       this.iFlagSourceVolt);//deleted by Zoe
      elem.setFlag( AbsElem.DATA_STUDY_AREA ,     this.iFlagStudyArea);
      elem.setFlag( AbsElem.DATA_SUST_FAULT ,     this.iFlagPermFaultRate);
      elem.setFlag( AbsElem.DATA_BOOST_TRIG ,     this.iFlagBoostTrigger);
      elem.setFlag( AbsElem.DATA_BUCK_TRIG ,      this.iFlagBuckTrigger);
      elem.setFlag( AbsElem.DATA_TAP_RATIO ,      this.iFlagTapRatio );
      elem.setFlag( AbsElem.DATA_TEMP_FAULT  ,    this.iFlagTempFaultRate  );
      elem.setFlag( AbsElem.DATA_TXFM_RATIO ,     this.iFlagTxfmRatio);
      elem.setFlag( AbsElem.DATA_UPGRADE_COST ,   this.iFlagUpgradeCost );
      elem.setFlag( AbsElem.DATA_YEAR ,           this.iFlagYear );
      elem.setFlag( AbsElem.DATA_ZONE ,           this.iFlagZone );

      return elem;
  }

  public String getConn1(){ return this.sConn1; }
  public String getConn2(){ return this.sConn2; }
  public String getConn3(){ return this.sConn3; }
}

//Untested code
// private void processShowTextForLoad(AbsElem elem ){
//      AbsElemGeom geom = elem.getElemGeomObj();
//
//      int showText;
//      int cntr=0;
//      for(int i=0; i<AbsElem.NUM_DATA_FIELD; i++){
//          showText = elem.getFlag(i) & 0x80000000; //in binary: 1000....0000
//          if( showText == 0x80000000 ){ cntr++; }
//      }
//      if( cntr>0) {
//          si[AbsElemGeom.SHOW_DATA] = new int[cntr];
//          cntr=0;
//          for(int i=0; i<AbsElem.NUM_DATA_FIELD; i++){
//              showText = elem.getFlag(i) & 0x80000000; //in binary: 1000....0000
//              if( showText == 0x80000000 ){
//                  si[AbsElemGeom.SHOW_DATA][cntr] = i;
//                  cntr++;
//                  elem.setFlag(i, elem.getFlag(i) & 0x70000000);//0111....1111
//              }
//          }
//      } else {
//          si[AbsElemGeom.SHOW_DATA] = null;
//      }
//
//      si[AbsElemGeom.SHOW_RESULT] = null;
//  }